<template>
  <div class="competition-list">
    <grid-content>
      <template #left>
        <a-card  class="card" size="small"  style="width: 100%">
          <a-form  layout="inline"  :model="queryForm" >
            <a-form-item style="margin-bottom: 10px" label="赛制">
              <a-select
                  style="width: 120px"
                  ref="select"
                  v-model:value="queryForm.type"
                  :options="COMPETITION_TYPE"
                  @focus="focus"
                  @change="handleChange"
              />
            </a-form-item>
            <a-form-item style="margin-bottom: 10px" label="状态">
              <a-select
                  ref="select"
                  v-model:value="queryForm.status"
                  style="width: 120px"
                  :options="COMPETITION_STATUS"
                  @focus="focus"
                  @change="handleChange"
              />
            </a-form-item>
            <a-form-item style="margin-bottom: 10px" label="类型">
              <a-select
                  ref="select"
                  v-model:value="queryForm.auth"
                  style="width: 120px"
                  :options="COMPETITION_AUTH"
                  @focus="focus"
                  @change="handleChange"
              />
            </a-form-item>
            <a-form-item style="margin-bottom: 10px" label="创建人">
              <a-input v-model:value="queryForm.nickName" placeholder="输入创建人昵称" />
            </a-form-item>
            <a-form-item style="margin-bottom: 10px" label="比赛名称">
              <a-row  :gutter="16">
                <a-col>
                  <a-input v-model:value="queryForm.title" placeholder="输入比赛名称" />
                </a-col>
                <a-col>
                  <a-button type="primary">查询</a-button>
                </a-col>
              </a-row>
            </a-form-item>
          </a-form>
          <a-table
              :scroll="{ x: 768 }"
              style="margin-top: 10px"
              :pagination="pagination"
              :columns="columns" :data-source="data">
            <template #bodyCell="{ column, text , record }">
              <template v-if="column.dataIndex === 'title'">
                <a>{{ text }}</a>
              </template>
              <template v-else-if="column.dataIndex === 'status'">
                <div v-if="record.type"> <a-tag color="cyan">{{getLabelByValue(COMPETITION_TYPE ,record.type)}}</a-tag> </div>
                <div style="margin: 3px 0" v-if="record.auth"><a-tag color="purple">{{getLabelByValue(COMPETITION_AUTH ,record.auth)}}</a-tag></div>
                <div><a-tag color="blue">{{getLabelByValue(COMPETITION_STATUS ,text)}}</a-tag></div>
              </template>
              <template v-else-if="column.dataIndex === 'startTime'">
                <span>{{text}}</span>
              </template>
              <template v-else-if="column.dataIndex === 'endTime'">
                <span>{{calculateMatchDuration(record.startTime,record.endTime)}}</span>
              </template>
            </template>
          </a-table>
        </a-card>
      </template>
      <template #right>
        <a-card  class="card" size="small" title="排行榜" style="width: 100%;position: sticky;top: 80px">

        </a-card>
      </template>
    </grid-content>
  </div>
</template>

<script lang="ts" setup>
import {calculateMatchDuration} from "@/utils/date";
import GridContent from "@/components/GridContent"
import {COMPETITION_TYPE,COMPETITION_AUTH,COMPETITION_STATUS,getLabelByValue} from "@/common/enum"
import {computed, reactive, ref} from 'vue';
import type { UnwrapRef } from 'vue';
import type { SelectProps } from 'ant-design-vue';
interface queryForm {
  type?: number;
  auth?: number;
  pwd?: number;
  nickName?: string;
  status?:number;
  title?:string;
}

const queryForm: UnwrapRef<queryForm> = reactive({

});
const handleChange = (value: string) => {
  //console.log(`selected ${value}`);
};
// const formItemLayout = computed(() => {
//   const { layout } = queryForm;
//   return layout === 'horizontal'
//       ? {
//         wrapperCol: { span: 22 },
//       }
//       : {};
// });

const current = ref(1)
const pageSize = ref(5);
const pagination = computed(() => ({
  total: 200,
  current: current.value,
  pageSize: pageSize.value,
}));

const columns = [
  {
    title: 'ID',
    dataIndex: 'id',
    key: 'id',
    width: 80,
  },
  {
    title: '比赛名称',
    dataIndex: 'title',
    key: 'title',
  },
  {
    title: '开始时间',
    dataIndex: 'startTime',
    key: 'startTime',
  },
  {
    title: '时长',
    dataIndex: 'endTime',
    key: 'endTime',
  },
  {
    title: '状态',
    dataIndex: 'status',
    key: 'status',
  },
  {
    title: '创建人',
    dataIndex: 'author',
    key: 'author',
  },
];

const data = [
  {
    id: '1',
    title: 'John Btitletitletitlerown',
    status: 1,
    auth:1,
    type:1,
    author: 'New York No. 1',
    startTime: '2023-02-04 00:00:00',
    endTime: '2023-02-05 12:32:03'
  },
  {
    id: '1',
    title: 'John Btitletitletitlerown',
    status: 1,
    author: 'New York No. 1',
    startTime: '2023 02-05 12:32:03',
    endTime: '2023 02-04 00:00:00'
  }, {
    id: '1',
    title: 'John Btitletitletitlerown',
    status: 1,
    author: 'New York No. 1',
    startTime: '2023 02-04 00:00:00',
    endTime: '2023 02-04 00:00:00'
  }, {
    id: '1',
    title: 'John Btitletitletitlerown',
    status: 1,
    author: 'New York No. 1',
    startTime: '2023 02-04 00:00:00',
    endTime: '2023 02-04 00:00:00'
  }, {
    id: '1',
    title: 'John Btitletitletitlerown',
    status: 1,
    author: 'New York No. 1',
    startTime: '2023 02-04 00:00:00',
    endTime: '2023 02-04 00:00:00'
  },


];



</script>
<style scoped>

</style>
